package com.island.controller.user;

import com.island.pojo.User;
import com.island.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserLogInOutController {
    @Autowired
    UserService userService;
    //1、登陆
    @RequestMapping("/login")
    public String login(String userCode, String userPassword, HttpServletRequest req){
        System.out.println("=========>进入controller");
        User user = userService.login(userCode, userPassword);
        if (user != null) {
            req.getSession().setAttribute("userSession", user);
            return "frame";
        }
        req.setAttribute("error", "用户名或密码错误");
        return "forward:/login.jsp";
    }

    //2.注销
    @RequestMapping("/logout")
    public String logout(HttpServletRequest req){
        req.getSession().removeAttribute("userSession");
        return "redirect:/login.jsp";
    }
}